# @Desc    : 分析趋势 day week month
# @Author  : meihongliang  
# @Time    : 2025-03-23 11:47
from dataclasses import dataclass
from typing import List

import pandas as pd


@dataclass
class BaseKLine:
    """基本值"""
    # day  open  high   low  close
    day: str
    open: float  # 开盘价
    high: float  # 最高价、最低价、收盘价
    low: float  # 最低价
    close: float  # 收盘价
    # volume: float # ?


class DayKLineType:
    """日趋势,尽量不沾染其他内容"""
    base_kline: BaseKLine
    type_of_today: str  # 上涨/下跌
    color_of_today: str
    trend_of_today: str  # 日趋势   十字星 乌云盖顶  扽
    trend_of_week: str  # 周趋势
    trend_of_month: str  # 月趋势
    history_kline: List[BaseKLine]  # 历史数据

    def __init__(self, base_kline: BaseKLine, history_kline: List[BaseKLine]):
        self.base_kline = base_kline
        self.history_kline = history_kline
        self.check_today()

    # 检查今日的状态
    def check_today(self):
        # 开盘 <> 收盘
        if self.base_kline.open < self.base_kline.close:
            self.type_of_today = '上涨'
            self.color_of_today = 'red/white'
        elif self.base_kline.open > self.base_kline.close:
            # 收盘价 小于 开盘价
            self.type_of_today = '下跌'
            self.color_of_today = 'green/black'
        else:
            self.type_of_today = '持平'
            self.trend_of_today = '十字星'

    # 检查3天还是5天还是2周还是2月
    def check_3_day_ago(self):
        # 检查3天前的，检查5天前的
        pass


class WeekTrend:
    """周趋势"""
    pass


if __name__ == '__main__':
    # 测试
    data = {
        'Date': ['2023-10-01', '2023-10-02', '2023-10-03', '2023-10-04', '2023-10-05'],
        'Open': [100, 105, 110, 108, 112],
        'High': [102, 108, 112, 111, 115],
        'Low': [98, 103, 108, 107, 110],
        'Close': [101, 107, 109, 110, 112]
    }
    df = pd.DataFrame(data)
    for k, v in df.iterrows():
        base_k = BaseKLine(day=v['Date'], open=v['Open'], high=v['High'], low=v['Low'], close=v['Close'])
        day_type = DayKLineType(base_kline=base_k, history_kline=[])
        print(day_type.__dict__)
